package util;

import java.sql.*;
import java.util.Properties;

/**
 * @author Hnmtuan
 * @version 1.0
 * @created 01-Aug-2011 3:13:10 PM
 */
public class MyObject {

    private static Connection _connection;
    public static String _connString;
    public static String _password;
    public static String _userName;
    public static String _driverManager;
    
    static {
        _connString = "";
        _password = "";
        _userName = "";
        _driverManager ="";
        _connection = null;
    }

    public MyObject(){
        
    }

    public static void CloseConnect() throws SQLException{
        if (_connection == null) { return ;}
        _connection.close();
    }
    
    public static void CloseConnectStatic() throws SQLException{
         if (_connection == null) { return ;}
        _connection.close();
    }



    public static void CreateConnect() throws SQLException, ClassNotFoundException{
        
        String l_driverManager = _driverManager;
        String l_connString = _connString;
        String l_userName = _userName;
        String l_password = _password;

        // Register Driver
        Class.forName(l_driverManager);        

        // Register Info
        Properties info = new Properties();
        info.setProperty("characterEncoding", "utf8");
        info.setProperty("user", l_userName);
        info.setProperty("password", l_password);
        
        // New Connection
        Connection conn = DriverManager.getConnection(l_connString, info);

        // Assig new connectiion
        _connection = conn;
    }

    public static void CreateConnectStatic() throws SQLException, ClassNotFoundException {

        String l_driverManager = "org.gjt.mm.mysql.Driver";
        String l_connString = "jdbc:mysql://localhost:3306/doansocket";
        String l_userName = "root";
        String l_password = "123456";

        // Register Driver
        Class.forName(l_driverManager);

        // Register Info
        Properties info = new Properties();
        info.setProperty("characterEncoding", "utf8");
        info.setProperty("user", l_userName);
        info.setProperty("password", l_password);

        // New Connection
        Connection conn = DriverManager.getConnection(l_connString, info);

        // Assig new connectiion
        _connection = conn;
        
    }

    public  String getDriverManager() {
        return _driverManager;
    }

    public void setDriverManager(String _driverManager) {
        MyObject._driverManager = _driverManager;
    }

    public static Connection getConnectionStatic (){
        return _connection;
    }

    public void setConnection(Connection _conn) {
        _connection = _conn;
    }

    public String getConnString() {
        return _connString;
    }

    public void setConnString(String _connString) {
        MyObject._connString = _connString;
    }

    public String getPassword() {
        return _password;
    }

    public void setPassword(String _password) {
        MyObject._password = _password;
    }

    public String getUserName() {
        return _userName;
    }

    public void setUserName(String _userName) {
        MyObject._userName = _userName;
    }

}